package TechStuff;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import Models.Point2D;
import TechStuff.RmiStarter;
import TechStuff.ServerInterface;


public class ServerStub
extends RmiStarter implements ServerInterface {
	private ServerInterface server;
	
	public ServerStub()
	{
		super(ServerInterface.class);
		doCustomRmiHandling();		
	}

	@Override
	public int registerClient() throws RemoteException {
		return server.registerClient();
	}

	@Override
	public void unregisterClient(int id) throws RemoteException {
		server.unregisterClient(id);
	}

	@Override
	public void doCustomRmiHandling() {
		String host = "localhost";
		try {
		    Registry registry = LocateRegistry.getRegistry(host);
		    server = (ServerInterface) registry.lookup(name);
		} catch (Exception e) {
		    System.err.println("Client exception: " + e.toString());
		    e.printStackTrace();
		}
	}

	@Override
	public void createClient(int id) throws RemoteException {
		server.createClient(id);
	}

	@Override
	public boolean movePiece(Point2D from, Point2D to, int id)
			throws RemoteException {
		return server.movePiece(from, to, id);
	}

	@Override
	public void resetGame() throws RemoteException {
		server.resetGame();
		
	}

}
